package first;

import java.time.Duration;
import java.time.LocalDateTime;

public final class PhoneBillCalculator {
    // 定义常量，替换魔术数字
    private static final long FREE_MINUTES = 20;
    private static final double RATE_FIRST_20_MINUTES = 0.05;
    private static final double RATE_AFTER_20_MINUTES = 0.10;
    private static final double BASE_COST_AFTER_20_MINUTES = 1.00;

    // 隐藏公共构造器
    private PhoneBillCalculator() {
    }

    public static double calculateBill(final LocalDateTime start, final LocalDateTime end) {
        // 处理夏令时时间转换，这里简单假设直接使用Duration计算能处理好夏令时情况
        // 实际可能需要更复杂的逻辑，比如判断时间是否跨越夏令时转换点
        Duration duration = Duration.between(start, end);
        long minutes = duration.toMinutes();
        if (minutes <= FREE_MINUTES) {
            return minutes * RATE_FIRST_20_MINUTES;
        } else {
            return BASE_COST_AFTER_20_MINUTES + (minutes - FREE_MINUTES) * RATE_AFTER_20_MINUTES;
        }
    }
}
